<?php

namespace App\Providers;

use App\Listeners\CompanyObserver;
use App\Models\Company;
use App\Services\MenuService;
use Illuminate\Support\Facades\Queue;
use Illuminate\Support\ServiceProvider;
use App\Services\Interfaces\MenuServiceInterface;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        // 注册菜单服务
        $this->app->singleton(MenuServiceInterface::class, function(){
            return new MenuService();
        });

        // 注册事件
        Company::observe(CompanyObserver::class);

        Queue::failing(function ($connection, $job, $data) {
            logger($job, $data);
        });
    }

    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        $this->app
            ->when(\App\Http\Controllers\Resources\CompanyController::class)
            ->needs(\App\Services\Interfaces\RepoServiceInterface::class)
            ->give(\App\Services\Repo\CompanyRepo::class);
        $this->app
            ->when(\App\Http\Controllers\Resources\AdminController::class)
            ->needs(\App\Services\Interfaces\RepoServiceInterface::class)
            ->give(\App\Services\Repo\AdminRepo::class);
        $this->app
            ->when(\App\Http\Controllers\Auth\PasswordController::class)
            ->needs(\App\Services\Interfaces\RepoServiceInterface::class)
            ->give(\App\Services\Repo\AdminRepo::class);
        $this->app
            ->when(\App\Http\Controllers\Resources\SimCardController::class)
            ->needs(\App\Services\Interfaces\RepoServiceInterface::class)
            ->give(\App\Services\Repo\SimCardRepo::class);
        $this->app
            ->when(\App\Http\Controllers\Resources\WxclientController::class)
            ->needs(\App\Services\Interfaces\RepoServiceInterface::class)
            ->give(\App\Services\Repo\WxClientRepo::class);
    }
}
